<template>
<view class="body">
	  <view class="title">选择培训专业</view>
	  <view class="list">
		<checkbox-group @change="bind">
		  <label class="content" v-for="(item,index) in arr" :key="item.name">
			<view class="weui-cell__hd">
			  <checkbox :value="item.name" :checked="item.checked"/>
			</view>
			<view class="weui-cell__bd">{{item.name}}</view>
		  </label>
		</checkbox-group>
	  </view>
</view>
</template>
<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			arr:[],
			key:''
		}
	},

	onLoad:function(e){
		this.key = e.key
		this.getTrain();
	},
	methods: {
		getTrain:function(){
			var that = this;
			request({
				url: 'job/getTrain',
				method: 'get',
				success: (res) => {
					if(res.data.code == 1){
						that.cateData(res.data.data)
					}
				}
			})
		},
		cateData:function(cate){
			var that = this
			if(this.key){
				let key = this.key.split(',')
				for(var x in cate){
					if(key.indexOf(cate[x]['name']) >= 0){
						cate[x]['checked'] = true
					}
				}
			}
			this.arr = cate
		},
		bind:function(e){
			var key = e.detail.value;
			key = key.join(',');
			var pages = getCurrentPages();
			var currPage = pages[pages.length - 1]; //当前页面
			var prevPage = pages[pages.length - 2]; //上一个页面
			if(prevPage.route == 'pages/user/info/personal'){
				prevPage.$vm.form.business = key
			}
			if(prevPage.route == 'pages/login/personal'){
				prevPage.$vm.form.business = key
				uni.setStorageSync('pForm',prevPage.$vm.form)
				prevPage.$vm.$forceUpdate();
			}
		}
	}
}
</script>
<style>
.body{padding:20rpx;}
.title{width:100%;text-align: center;}
.list{width:100%;}
.content{justify-content: flex-start;width:100%;align-items: center;
    height:38px;display: flex;padding:10rpx 0 5rpx 10rpx;border-bottom: 1px solid #c0c0c0;}
</style>